import BasePainting from "../../standard/entities/Painting/BasePainting";

export default class RectPainting extends BasePainting {
    constructor(rect, color = '#f00') {
        super();
        this.rect = rect;
        this.color = color;
    }


    onPainterLoaded(painter) {
        super.onPainterLoaded(painter);
        painter.globalAlpha = 0.2;
        painter.fillStyle = this.color;
    }

    beDrawn(painter) {
        painter.drawInSession(() => {
            painter.beginPath();
            painter.translate(this.rect.centre.x, this.rect.centre.y);
            painter.rotate(this.rect.angle * Math.PI / 180);
            painter.rectByPoint(this.rect.getHornPoints()[0], this.rect.width, this.rect.height);
            painter.fill();
        });
    }
}